$.fn.fmatter.showlink = function(c, a, l) {
    var e = {
        baseLinkUrl: a.baseLinkUrl,
        showAction: a.showAction,
        addParam: a.addParam || "",
        target: a.target,
        idName: a.idName
    },
    f = "",
    g = "",
    h;
    if (a.colModel !== undefined && a.colModel.formatoptions !== undefined) {
        e = $.extend({},
        e, a.colModel.formatoptions)
    }
    if (e.target) {
        f = ' target="' + e.target + '"'
    }
    if (e.title) {
        g = ' title="' + e.title + '"'
    }
    var b = null;
    if (e.idValue == "id") {
        b = a.rowId
    } else {
        b = l[e.idValue];
        if ((b == undefined || b == "") && e.idValue.indexOf(".") > -1) {
            var d = l;
            $.each(e.idValue.split("."),
            function(m, n) {
                d = d[n]
            });
            b = d
        }
    }
    h = e.baseLinkUrl + e.showAction + "?" + e.idName + "=" + b + e.addParam;
    if ($.fmatter.isString(c) || $.fmatter.isNumber(c)) {
        return "<a " + f + g + ' href="' + h + '">' + c + "</a>"
    }
    return $.fn.fmatter.defaultFormat(c, a)
};
var Grid = function() {
    var a = false;
    return {
    	//默认增加属性相关   being
        initGridDefault: function() {
            $.extend($.ui.multiselect, {
                locale: {
                    addAll: "全部添加",
                    removeAll: "全部移除",
                    itemsCount: "已选择项目列表"
                }
            });
            $.extend($.jgrid.ajaxOptions, {
                dataType: "json"
            });
            //ajax属性相关
            $.extend($.jgrid.defaults, {
                datatype: "json",
                loadui: false,
                loadonce: false,
                filterToolbar: {},
                ignoreCase: true,
                prmNames: {
                    npage: "npage"
                },
                jsonReader: {
                    repeatitems: false,
                    root: "content",
                    total: "totalPages",
                    records: "totalElements"
                },
                treeReader: {
                    level_field: "extraAttributes.level",
                    parent_id_field: "extraAttributes.parent",
                    leaf_field: "extraAttributes.isLeaf",
                    expanded_field: "extraAttributes.expanded",
                    loaded: "extraAttributes.loaded",
                    icon_field: "extraAttributes.icon"
                },
                autowidth: true,
                rowNum: 15,
                page: 1,
                altclass: "ui-jqgrid-evennumber",
                height: "stretch",
                viewsortcols: [true, "vertical", true],
                mtype: "GET",
                viewrecords: true,
                rownumbers: true,
                recordpos: "left",
                gridview: true,
                altRows: true,
                sortable: false,
                multiboxonly: true,
                multiselect: true,
                multiSort: false,
                forceFit: false,
                shrinkToFit: true,
                sortorder: "desc",
                sortname: "id",
                ajaxSelectOptions: {
                    cache: true
                },
                loadError: function(d, e, b, c) {
                    Global.notify("error", "表格数据加载处理失败,请尝试刷新或联系管理员!")
                },
                subGridOptions: {
                    reloadOnExpand: false
                }
            });
            //动态查询相关
            $.extend($.jgrid.search, {
                multipleSearch: true,
                multipleGroup: true,
                width: 700,
                jqModal: false,
                searchOperators: true,
                stringResult: true,
                searchOnEnter: true,
                defaultSearch: "bw",
                operandTitle: "点击选择查询方式",
                odata: [{
                    oper: "eq",
                    text: "等于\u3000\u3000"
                },
                {
                    oper: "ne",
                    text: "不等\u3000\u3000"
                },
                {
                    oper: "lt",
                    text: "小于\u3000\u3000"
                },
                {
                    oper: "le",
                    text: "小于等于"
                },
                {
                    oper: "gt",
                    text: "大于\u3000\u3000"
                },
                {
                    oper: "ge",
                    text: "大于等于"
                },
                {
                    oper: "bw",
                    text: "开始于"
                },
                {
                    oper: "bn",
                    text: "不开始于"
                },
                {
                    oper: "in",
                    text: "属于\u3000\u3000"
                },
                {
                    oper: "ni",
                    text: "不属于"
                },
                {
                    oper: "ew",
                    text: "结束于"
                },
                {
                    oper: "en",
                    text: "不结束于"
                },
                {
                    oper: "cn",
                    text: "包含\u3000\u3000"
                },
                {
                    oper: "nc",
                    text: "不包含"
                },
                {
                    oper: "nu",
                    text: "不存在"
                },
                {
                    oper: "nn",
                    text: "存在"
                },
                {
                    oper: "bt",
                    text: "介于"
                }],
                operands: {
                    eq: "=",
                    ne: "!",
                    lt: "<",
                    le: "<=",
                    gt: ">",
                    ge: ">=",
                    bw: "^",
                    bn: "!^",
                    "in": "=",
                    ni: "!=",
                    ew: "|",
                    en: "!@",
                    cn: "~",
                    nc: "!~",
                    nu: "#",
                    nn: "!#",
                    bt: "~~"
                }
            });
           
            $.jgrid.extend({
                refresh: function() {
                    this.each(function() {
                        var b = this;
                        if (!b.grid) {
                            return
                        }
                        $(b).jqGrid("setGridParam", {
                            datatype: "json"
                        }).trigger("reloadGrid")
                    })
                },
                search: function(b) {
                    this.each(function() {
                        var e = this;
                        if (!e.grid) {
                            return
                        }
                        var c = $(e).jqGrid("getGridParam", "url");
                        for (var d in b) {
                            c = AddOrReplaceUrlParameter(c, d, b[d])
                        }
                        $(e).jqGrid("setGridParam", {
                            url: c,
                            page: 1
                        }).trigger("reloadGrid")
                    })
                },
                exportExcelLocal: function(b) {
                    this.each(function() {
                        var f = this;
                        if (!f.grid) {
                            return
                        }
                        if (!confirm("确认导出当前页面 " + f.p.caption + " 数据为Excel下载文件？")) {
                            return
                        }
                        var e = new Array();
                        e = $(f).getDataIDs();
                        var m = f.p.colModel;
                        var p = f.p.colNames;
                        var h = "";
                        for (k = 0; k < p.length; k++) {
                            var n = m[k];
                            if (n.hidedlg || n.hidden || n.disableExport) {
                                continue
                            }
                            h = h + p[k] + "\t"
                        }
                        h = h + "\n";
                        for (i = 0; i < e.length; i++) {
                            data = $(f).getRowData(e[i]);
                            for (j = 0; j < p.length; j++) {
                                var n = m[j];
                                if (n.hidedlg || n.hidden || n.disableExport) {
                                    continue
                                }
                                var g = data[n.name];
                                var l = null;
                                if (n.searchoptions && n.searchoptions.value) {
                                    l = n.searchoptions.value
                                } else {
                                    if (n.editoptions && n.editoptions.value) {
                                        l = n.editoptions.value
                                    }
                                }
                                if (l) {
                                    g = l[g]
                                }
                                if (g.indexOf("<") > -1 && g.indexOf(">") > -1) {
                                    g = $(g).text()
                                }
                                if (g == "") {
                                    g = data[n.name]
                                }
                                if (g == "null" || g == null) {
                                    g = ""
                                }
                                g = g.replace(/\&nbsp;/g, "");
                                h = h + g + "\t"
                            }
                            h = h + "\n"
                        }
                        h = h + "\n";
                        var c = $('<form method="post" target = "_blank" action="' + WEB_ROOT + '/admin/util/grid/export"></form>').appendTo($("body"));
                        var o = $('<input type="hidden" name="exportDatas"/>').appendTo(c);
                        var d = $('<input type="hidden" name="fileName"/>').appendTo(c);
                        d.val("export-data.xls");
                        o.val(h);
                        c.submit();
                        c.remove()
                    })
                },
                refreshRowIndex: function() {
                    var b = $(this);
                    $.each($(b).jqGrid("getDataIDs"),
                     function(c, d) {
                        $(b).find("#" + d).find("input,select").each(function() {
                            var e = $(this).attr("name");
                            $(this).attr("name", e.substring(0, e.indexOf("[") + 1) + c + e.substring(e.indexOf("]"), e.length))
                        })
                    })
                },
                getAtLeastOneSelectedItem: function(g) {
                    var f = $(this);
                    var d = [];
                    var e = jQuery(f).jqGrid("getGridParam", "selarrrow");
                    if (e.length > 0) {
                        for (var b = 0; b < e.length; b++) {
                            var c = $("#jqg_" + jQuery(f).attr("id") + "_" + e[b]).is(":disabled");
                            if (!c) {
                                d.push(e[b])
                            }
                        }
                    } else {
                        var h = jQuery(f).jqGrid("getGridParam", "selrow");
                        if (h) {
                            d.push(h)
                        }
                    }
                    if (g) {
                        jQuery(f).find("table.jqsubgrid").each(function() {
                            var n = $(this).jqGrid("getGridParam", "selarrrow");
                            for (var l = 0; l < n.length; l++) {
                                var m = $("#jqg_" + jQuery(this).attr("id") + "_" + e[l]).is(":disabled");
                                if (!m) {
                                    d.push(n[l])
                                }
                            }
                        })
                    }
                    if (d.length == 0) {
                        Global.notify("error", "请至少选择一条行项目！");
                        return false
                    } else {
                        return d
                    }
                },
                getOnlyOneSelectedItem: function(g) {
                    var f = $(this);
                    var d = [];
                    var e = jQuery(f).jqGrid("getGridParam", "selarrrow");
                    if (e.length > 0) {
                        for (var b = 0; b < e.length; b++) {
                            var c = $("#jqg_" + jQuery(f).attr("id") + "_" + e[b]).is(":disabled");
                            if (!c) {
                                d.push(e[b])
                            }
                        }
                    } else {
                        var h = jQuery(f).jqGrid("getGridParam", "selrow");
                        if (h) {
                            d.push(h)
                        }
                    }
                    if (d.length == 0) {
                        if (g) {
                            Global.notify("error", "请选取操作项目")
                        }
                        return false
                    } else {
                        if (d.length > 1) {
                            Global.notify("error", "只能选择一条操作项目");
                            return false
                        }
                        return d[0]
                    }
                },
                getSelectedItem: function() {
                    var c = $(this);
                    var b = jQuery(c).jqGrid("getGridParam", "selarrrow");
                    return b.join()
                },
                getSelectedRowdatas: function() {
                    var b = $(this);
                    var c = [];
                    var e = b.jqGrid("getGridParam", "selarrrow");
                    if (e) {
                        $.each(e,
                        function(g, h) {
                            var l = b.jqGrid("getRowData", h);
                            l.id = h;
                            c.push(l)
                        })
                    } else {
                        var d = b.jqGrid("getGridParam", "selrow");
                        if (d) {
                            var f = b.jqGrid("getRowData", d);
                            f.id = d;
                            c.push(f)
                        }
                    }
                    return c
                },
                getSelectedRowdata: function() {
                    var b = $(this);
                    var c = b.jqGrid("getGridParam", "selrow");
                    if (c) {
                        return b.jqGrid("getRowData", c)
                    }
                },
                getDirtyRowdatas: function() {
                    var l = $(this);
                    var g = [];
                    var f = l.jqGrid("getGridParam", "colModel");
                    var d = [];
                    $.each(f,
                    function(o, n) {
                        if (n.editable) {
                            d.push(n.name)
                        }
                    });
                    var b = l.jqGrid("getDataIDs");
                    var h = 0;
                    $.each(b,
                    function(n, o) {
                        if (!Util.startWith(o, "-") && o != "") {
                            h++
                        }
                    });
                    var e = BooleanUtil.toBoolean(l.attr("data-clone"));
                    $.each(b,
                    function(n, q) {
                        var p = l.jqGrid("getRowData", q);
                        if (BooleanUtil.toBoolean(p["extraAttributes.dirtyRow"])) {
                            if (Util.startWith(q, "-")) {
                                q = ""
                            }
                            var o = {
                                id: q
                            };
                            $.each(d,
                            function(s, r) {
                                o[r] = p[r]
                            });
                            o._arrayIndex = p._arrayIndex;
                            if (p["extraAttributes.operation"]) {
                                o["extraAttributes.operation"] = p["extraAttributes.operation"]
                            }
                            g.push(o)
                        }
                    });
                    var m = l.jqGrid("getGridParam", "batchEntitiesPrefix");
                    if (m) {
                        var c = {};
                        $.each(g,
                        function(n, p) {
                            var o = p._arrayIndex;
                            delete p._arrayIndex;
                            if (o == undefined || o == "") {
                                o = h;
                                h++
                            }
                            $.each(p,
                            function(r, q) {
                                c[m + "[" + o + "]." + r] = q
                            })
                        });
                        return c
                    }
                    return g
                },
                insertNewRowdata: function(f) {
                    var b = $(this);
                    var e = null;
                    var d = b.jqGrid("getDataIDs");
                    $.each(d,
                    function(g, l) {
                        var h = b.jqGrid("getRowData", l);
                        if (!BooleanUtil.toBoolean(h["extraAttributes.dirtyRow"])) {
                            e = l;
                            return false
                        }
                    });
                    var c = -Math.floor(new Date().getTime() + Math.random() * 100 + 100);
                    f["extraAttributes.dirtyRow"] = true;
                    if (e) {
                        b.jqGrid("addRowData", c, f, "before", e)
                    } else {
                        b.jqGrid("addRowData", c, f, "last")
                    }
                    return c
                },
                setEditingRowdata: function(l, c) {
                    var b = $(this);
                    var d = b.find("tbody");
                    for (var f in l) {
                        var g = "input[name='" + f + "'],select[name='" + f + "'],textarea[name='" + f + "']";
                        var e = d.find(g);
                        if (c == false) {
                            if ($.trim(e.val()) != "") {
                                continue
                            }
                        }
                        var h = l[f];
                        e.val(h).attr("title", h);
                        if (e.is("select")) {
                            e.select2({
                                openOnEnter: false,
                                placeholder: "请选择...",
                                matcher: function(n, q) {
                                    var m = Pinyin.getCamelChars(q) + "";
                                    var p = m.toUpperCase().indexOf(n.toUpperCase()) == 0;
                                    var o = q.toUpperCase().indexOf(n.toUpperCase()) == 0;
                                    return (p || o)
                                }
                            })
                        }
                    }
                },
                getEditingRowdata: function() {
                    var b = $(this);
                    var d = b.find("tbody");
                    var e = {};
                    var c = "input,select,textarea";
                    d.find(c).each(function() {
                        var f = $(this);
                        e[f.attr("name")] = f.val()
                    });
                    return e
                },
                isEditingMode: function(d) {
                    var b = $(this);
                    var c = b.find('tr[editable="1"]');
                    if (c.size() > 0) {
                        if (d == undefined) {
                            return true
                        }
                        if (d === true) {
                            alert("请先保存或取消正在编辑的表格数据行项后再操作")
                        } else {
                            alert(d)
                        }
                        return true
                    }
                    return false
                },
                sumColumn: function(d, f) {
                    var b = $(this);
                    if (f == undefined) {
                        f = 2
                    }
                    var e = b.jqGrid("getCol", d, false, "sum");
                    var c = Math.pow(10, f);
                    return Math.round(e * c) / c
                },
                getDataFromBindSeachForm: function(d) {
                    var b = $(this);
                    var c = b.jqGrid("getGridParam", "bindSearchFormData");
                    var e = c[d];
                    return e
                }
            });
            a = true
        },
        initAjax: function(b) {
            if (b == undefined) {
                b = $("body")
            }
            $('table[data-grid="table"],table[data-grid="items"]', b).each(function() {
                Grid.initGrid($(this))
            })
        },
        initGrid: function(X, F) {
            if (!a) {
                Grid.initGridDefault()
            }
            var ak = $(X);
            if (ak.hasClass("ui-jqgrid-btable")) {
                return
            }
            if (ak.attr("id") == undefined) {
                ak.attr("id", "grid_" + new Date().getTime())
            }
            if (F == undefined && ak.data("gridOptions") == undefined) {
                alert("Grid options undefined: class=" + ak.attr("class"));
                return
            }
            var x = $.extend(true, {}, ak.data("gridOptions"), F);
            var d = ak.attr("data-grid");
            var I = null;
            var ac = ak.attr("id") + "-context-menu-container";
            var Y = null;
            var f = (d == "items" ? false: true);
            var J = (d == "items" ? false: true);
            var M = $.extend(true, {},$.jgrid.defaults, {
	               filterToolbar: J,
	               multiselect: f,
	               contextMenu: true,
	               columnChooser: true,
	               exportExcelLocal: true,
            	   viewsortcols: d == "items" ? [true, "vertical", false] : [true, "vertical", true],
                   altRows: d == "items" ? false: true,
                   hoverrows: d == "items" ? false: true,
                   pgbuttons: d == "items" ? false: true,
                   pginput: d == "items" ? false: true,
                   rowList: d == "items" ? [] : [10, 15, 20, 50, 100, 200, 500, 1000, 2000], 
                   formatter: {
	                    integer: {
	                        defaultValue: ""
	                    },
	                    number: {
	                        decimalSeparator: ".",
	                        thousandsSeparator: ",",
	                        decimalPlaces: 2,
	                        defaultValue: ""
	                    },
	                    currency: {
	                        decimalSeparator: ".",
	                        thousandsSeparator: ",",
	                        decimalPlaces: 2,
	                        defaultValue: ""
	                    }
                   },
                   cmTemplate: {
                	   sortable: d == "items" ? false: true
                   },
                   inlineNav: {}
            },x);
            
            if ($.isFunction(M.url)) {
                M.url = M.url.call(ak)
            }
            if (M.url == undefined) {
                M.url = ak.attr("data-url")
            }
            if (M.url == undefined) {
                M.datatype = "local"
            }
           
            if (M.pager == undefined || M.pager) {
                I = ak.attr("id") + "_pager";
                $("<div id='" + I + "'/>").insertAfter(ak);
                M.pager = "#" + I
            } else {
                M.toppager = false
            }
            
            if (M.treeGrid) {
                M.rownumbers = false
            }
            if (x.editurl == undefined && d == "items") {
                M.editurl = "clientArray"
            }
            if (x.delurl == undefined && d == "items") {
                M.delurl = "clientArray"
            }
            if (M.editurl == "clientArray") {
                M.cellsubmit = M.editurl
            } else {
                M.cellurl = M.editurl
            }
            var U = 0;
            var T = false;
            var S = false;
            var V = [];
            $.each(M.colModel,function(ay, ax) {
                    if (ax.frozen) {
                         T = true
                     }
                    ax = $.extend(true,  {
                    	   editoptions: { rows: 1},
                           searchoptions: {
                                clearSearch: false,
                                searchhidden: true,
                                sopt: ["cn", "bw", "bn", "eq", "ne", "nc", "ew", "en"],
                                defaultValue: "",
                                buildSelect: function(aG) {
                                    if (aG == null) {
                                        aG = data
                                    }
                                    var aF = "<select>";
                                    aF += "<option value=''></option>";
                                    for (var aE in aG) {
                                        aE = aE + "";
                                        aF += ("<option value='" + aE + "'>" + aG[aE] + "</option>")
                                    }
                                    aF += "</select>";
                                    return aF
                                }
                            }},ax);
                        if (ax.name == "id") {
                            S = true
                        }
                        if (ax.name.toLowerCase() == "todo") {
                            ax.formatter = function(aG, aE, aH, aF) {
                                return "TODO"
                            }
                        }
                        if (ax.responsive) {
                            if (ax.hidden == undefined) {
                                var aw = $(window).width();
                                var az = ax.responsive;
                                if (az == "sm") {
                                    if (aw < 768) {
                                        ax.hidden = true
                                    }
                                } else {
                                    if (az == "md") {
                                        if (aw < 992) {
                                            ax.hidden = true
                                        }
                                    } else {
                                        if (az == "lg") {
                                            if (aw < 1200) {
                                                ax.hidden = true
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (ax.formatter == "currency") {
                            ax = $.extend({},{width: 80,align: "right"}, ax);
                            ax.formatoptions = $.extend({},ax.formatoptions, {
	                                decimalSeparator: ".",
	                                thousandsSeparator: ",",
	                                decimalPlaces: 2,
	                                prefix: "",
	                                defaultValue: ""
	                        });
                            ax.searchoptions = $.extend({},
                            ax.searchoptions, {sopt: ["eq", "ne", "ge", "le", "gt", "lt"]})
                        }
                        if (ax.formatter == "percentage") {
                            ax = $.extend(true, {width: 50,align: "right"},ax);
                            ax.formatter = function(aG, aE, aH, aF) {
                                if (aG) {
                                    return Math.round(aG * 10000) / 100 + "%"
                                } else {
                                    return aG
                                }
                            }
                        }
                        if (ax.stype == "date" || ax.sorttype == "date" || ax.formatter == "date" || ax.formatter == "timestamp") {
                            if (ax.formatter == "timestamp") {
                                ax = $.extend(true, {
                                    width: 150,
                                    fixed: true,
                                    align: "center",
                                    formatoptions: {
                                        srcformat: "Y-m-d H:i:s",
                                        newformat: "Y-m-d H:i:s"
                                    }
                                },ax);
                                ax.formatter = "date"
                            } else {
                                ax = $.extend(true, {
                                    width: 120,
                                    fixed: true,
                                    align: "center",
                                    formatoptions: {
                                        newformat: "Y-m-d"
                                    }
                                },
                                ax)
                            }
                            ax.searchoptions = $.extend({},
                            ax.searchoptions, {
                                sopt: ["bt", "eq", "ne", "ge", "le", "gt", "lt"],
                                dataInit: function(aF) {
                                    var aE = $(aF);
                                    $(aF).daterangepicker($.extend(true, $.fn.daterangepicker.defaults, ax.searchoptions.daterangepicker),
                                    function(aH, aG) {
                                        $(aF).focus()
                                    });
                                    $(aF).off("focus")
                                }
                            });
                            ax.editoptions = $.extend(ax.editoptions, {
                                dataInit: function(aE) {
                                    if (ax.editoptions.time) {
                                        $(aE).datetimepicker({
                                            language: "zh-CN",
                                            autoclose: true,
                                            todayBtn: true,
                                            minuteStep: 10,
                                            format: "yyyy-mm-dd hh:ii"
                                        })
                                    } else {
                                        $(aE).datepicker({
                                            language: "zh-CN",
                                            autoclose: true,
                                            todayBtn: true,
                                            format: "yyyy-mm-dd"
                                        })
                                    }
                                }
                            })
                        }
                        if (ax.formatter == "showlink") {
                            ax = $.extend(true, {
                                formatoptions: {
                                    idValue: "id",
                                    target: "modal-ajaxify"
                                }
                            },
                            ax)
                        }
                        if (ax.formatter == "integer") {
                            ax = $.extend(true, {
                                width: 60,
                                align: "center",
                                formatoptions: {
                                    defaultValue: ""
                                },
                                searchoptions: {
                                    sopt: ["eq", "ne", "ge", "le", "gt", "lt"]
                                }
                            },
                            ax)
                        }
                        if (ax.formatter == "number") {
                            ax.sorttype = ax.formatter;
                            ax.edittype = ax.formatter;
                            ax = $.extend(true, {
                                width: 60,
                                align: "right",
                                formatoptions: {
                                    defaultValue: ""
                                },
                                searchoptions: {
                                    sopt: ["eq", "ne", "ge", "le", "gt", "lt"]
                                }
                            },
                            ax)
                        }
                        if (ax.name == "id") {
                            ax = $.extend(true, {
                                width: 80,
                                align: "center",
                                title: false,
                                formatter: function(aH, aF, aJ, aG) {
                                    if (aH && aH.length > 5) {
                                        var aE = aH.length;
                                        var aI = aH.substring(aE - 5, aE);
                                        return "<span data='" + aH + "' onclick='$(this).html($(this).attr(\"data\"))'>..." + aI + "</span>"
                                    } else {
                                        return "<span>" + aH + "</span>"
                                    }
                                },
                                frozen: true
                            },
                            ax);
                            ax.searchoptions = $.extend(true, ax.searchoptions, {
                                sopt: ["eq", "ne", "ge", "le", "gt", "lt"]
                            })
                        }
                        if (ax.formatter == "checkbox") {
                            ax.edittype = ax.formatter;
                            ax = $.extend(true, {
                                width: 60,
                                align: "center",
                                formatter: "checkbox",
                                stype: "select"
                            },
                            ax);
                            ax.searchoptions.value = {
                                "": "",
                                "true": "是",
                                "false": "否"
                            };
                            ax.editoptions.value = "true:false"
                        }
                        if (ax.edittype == undefined || ax.edittype == "text" || ax.edittype == "select" || ax.edittype == "textarea") {
                            var c = ax.editoptions.dataInit;
                            ax.editoptions = $.extend(ax.editoptions, {
                                dataInit: function(aF) {
                                    var aE = $(aF);
                                    aE.removeClass("editable").addClass("form-control").attr("autocomplete", "off").css({
                                        width: "100%"
                                    });
                                    if (c) {
                                        c.call(this, aF)
                                    }
                                    if (ax.editoptions.updatable == false) {
                                        var aG = ak.jqGrid("getSelectedRowdata");
                                        if (aG && aG.id) {
                                            aE.attr("disabled", true)
                                        } else {
                                            if (!aE.attr("placeholder")) {
                                                aE.attr("placeholder", "创建后不可修改");
                                                aE.attr("title", "创建后不可修改")
                                            }
                                        }
                                    }
                                    if (aE.is("input[type='text']")) {
                                        aE.blur(function() {
                                            aE.val($.trim(aE.val()))
                                        })
                                    }
                                    if (aE.is("select")) {
                                        aE.select2({
                                            openOnEnter: false,
                                            placeholder: "请选择...",
                                            matcher: function(aI, aL) {
                                                var aH = Pinyin.getCamelChars(aL) + "";
                                                var aK = aH.toUpperCase().indexOf(aI.toUpperCase()) == 0;
                                                var aJ = aL.toUpperCase().indexOf(aI.toUpperCase()) == 0;
                                                return (aK || aJ)
                                            }
                                        })
                                    }
                                    if (ax.editoptions.spellto) {
                                        aE.change(function() {
                                            var aH = {};
                                            aH[ax.editoptions.spellto] = Pinyin.getCamelChars($.trim(aE.val()));
                                            ak.jqGrid("setEditingRowdata", aH)
                                        })
                                    }
                                }
                            })
                        }
                        if (ax.formatter == "select") {
                            ax.searchoptions.sopt = ["eq", "ne"];
                            if (ax.edittype == undefined) {
                                ax.edittype = "select"
                            }
                            if (ax.stype == undefined) {
                                ax.stype = "select"
                            }
                            if (typeof ax.searchoptions.value === "function") {
                                ax.searchoptions.value = ax.searchoptions.value.call(ak)
                            }
                            if (ax.searchoptions.valueJsonString) {
                                ax.searchoptions.value = {
                                    "": ""
                                };
                                var aD = $.parseJSON(ax.searchoptions.valueJsonString);
                                for (var aC in aD) {
                                    ax.searchoptions.value[aC] = aD[aC]
                                }
                            }
                            ax.editoptions = $.extend(true, {
                                value: ax.searchoptions.value
                            },
                            ax.editoptions)
                        }
                        if (!ax.hidden) {
                            if (ax.width) {
                                U += ax.width
                            } else {
                                U += 300
                            }
                        }
                        if (ax.hasOwnProperty("searchoptions")) {
                            var aA = ax.searchoptions;
                            if (aA.hasOwnProperty("defaultValue") && aA.defaultValue != "") {
                                var aB = ax.index;
                                if (aB == undefined) {
                                    aB = ax.name
                                }
                                V[V.length++] = {
                                    field: aB,
                                    op: ax.searchoptions.sopt[0],
                                    data: aA.defaultValue
                                }
                            }
                        }
                        M.colModel[ay] = ax
             });
            if (M.filterToolbar) {
                if (M.postData == undefined) {
                    M.postData = {}
                }
                var D = M.postData;
                var B = {};
                if (D.hasOwnProperty("filters")) {
                    B = JSON.parse(D.filters)
                }
                var n = [];
                if (B.hasOwnProperty("rules")) {
                    n = B.rules
                }
                $.each(V,
                function(aw, c) {
                    var ax = false;
                    $.each(n,
                    function(ay, az) {
                        if (c.field == az.field) {
                            ax = true;
                            return
                        }
                    });
                    if (ax == false) {
                        n.push(c)
                    }
                });
                if (n.length > 0) {
                    B.groupOp = "AND";
                    B.rules = n;
                    D._search = true;
                    D.filters = JSON.stringify(B)
                }
            }
            ak.jqGrid(M)
            
            if (M.setGroupHeaders) {
                ak.jqGrid("setGroupHeaders", $.extend(true, {
                    useColSpanStyle: true
                },
                M.setGroupHeaders))
            }
           
            if (M.pager || M.toppager) {
                var N = $(M.pager);
                var au = Util.notSmallViewport();
                if (au) {
                    au = (d == "items" ? false: true)
                }
                var am = Util.notSmallViewport();
                if (am) {
                    am = (d == "items" ? false: true)
                }
                ak.jqGrid("navGrid", M.pager, {
                    edit: false,
                    add: false,
                    del: false,
                    refresh: au,
                    search: au,
                    position: "right",
                    cloneToTop: true
                });
                if (M.columnChooser) {
                    var e = {
                        caption: "",
                        buttonicon: "ui-icon-battery-2",
                        position: "first",
                        title: "设定显示列和顺序",
                        onClickButton: function() {
                            var c = ak.jqGrid("getGridParam", "width");
                            ak.jqGrid("columnChooser", {
                                width: 470,
                                done: function(aw) {
                                    if (aw) {
                                        this.jqGrid("remapColumns", aw, true);
                                        ak.jqGrid("setGridWidth", c, false)
                                    } else {}
                                }
                            })
                        }
                    };
                    if (M.pager) {
                        ak.jqGrid("navButtonAdd", M.pager, e)
                    }
                    if (M.toppager) {
                        ak.jqGrid("navButtonAdd", M.toppager, e)
                    }
                }
                var at = Util.notSmallViewport();
                if (at) {
                    at = (d == "items" ? false: true)
                }
                if (M.exportExcelLocal && at) {
                    var y = {
                        caption: "",
                        buttonicon: "ui-icon-arrowthickstop-1-s",
                        position: "first",
                        title: "导出当前显示数据",
                        onClickButton: function() {
                            ak.jqGrid("exportExcelLocal", M.exportExcelLocal)
                        }
                    };
                    if (M.pager) {
                        ak.jqGrid("navButtonAdd", M.pager, y)
                    }
                }
             
        
               
                N.find(".navtable").css("float", "right");
                ak.jqGrid("navSeparatorAdd", M.pager, {
                    position: "first"
                });

               
            }
            
            setTimeout(function() {
            	Grid.refreshWidth();
            },1000);
            if (T) {
                ak.jqGrid("setFrozenColumns")
            }
            ak.jqGrid("gridResize", {
                minWidth: 500,
                minHeight: 100
            });
            
      
            
          
         
           
        },
        refreshWidth: function() {
            $("table.ui-jqgrid-btable:visible").each(function() {
                var c = $(this);
                var d = c.jqGrid("getGridParam", "width");
                var b = c.closest("div.ui-jqgrid").parent("div").width();
                if (d != b) {
                    c.jqGrid("setGridWidth", b);
                    var e = $(this).jqGrid("getGridParam", "groupHeader");
                    if (e) {
                        c.jqGrid("destroyGroupHeader");
                        c.jqGrid("setGroupHeaders", e)
                    }
                }
            })
        },
        initRecursiveSubGrid: function(f, c, e, h) {
            var b = $("<table data-grid='table' class='ui-jqgrid-subgrid'/>").appendTo($("#" + f));
            var d = b.closest("table.ui-jqgrid-btable").data("gridOptions");
            d.url = Util.AddOrReplaceUrlParameter(d.url, "search['EQ_" + e + "']", c);
            d.inlineNav = $.extend(true, {
                addParams: {
                    addRowParams: {
                        extraparam: {}
                    }
                }
            },
            d.inlineNav);
            d.inlineNav.addParams.addRowParams.extraparam[e] = c;
            d.parent = e;
            if (h) {
                d.postData = {}
            }
            b.data("gridOptions", d);
            Grid.initGrid(b);
            var g = $("#" + f).parent().closest(".ui-jqgrid-btable:not(.ui-jqgrid-subgrid)");
            if (d.gridDnD && g.hasClass("ui-jqgrid-dndtable")) {
                $("#" + f).find(".ui-icon-arrow-4:first").click()
            }
        },
        initSubGrid: function(e, d, c) {
            var b = $("<table data-grid='table' class='ui-jqgrid-subgrid'/>").appendTo($("#" + e));
            b.data("gridOptions", c);
            Grid.initGrid(b)
        }
    }
} ();